﻿/**
* @file port.h
* @brief this is a brief description
* @details this is the detail description.
* @author fulong 
* @data 2014/10/23
* @version 1.0
* @par Copyright (c):
* @par First build
*     version: fulong 
*     data: 2014/10/23
*/
#ifndef __PORT_H__
#define __PORT_H__
#include "../hal_include/hal_types.h"
//about i2c
/*!< set waht the sda of i2c port is */
#define I2C_SDA_PORT(portdata)  p3_4=(portdata)
#define i2c_sda_output() set_output(3,4)
#define i2c_sda_input() set_input(3,4)
#define READ_I2C_SDA_PORT() p3_4
/*!< set waht the scl of i2c port is */
#define I2C_SCL_PORT(portdata) p3_5=(portdata)
#define i2c_sck_output() set_output(3,5)
//about output
#define OUTPUT_CTRL_ON() p5_1=1
#define set_output_led_ctrl_output() set_output(5,1)

/*!< test output port*/
//#define OUTPUT_TEST

#define OUT5(odata) p2_7=(odata)
#define OUT4(odata) p9_0=(odata)
#define OUT3(odata) p9_1=(odata)
#define OUT2(odata) p9_2=(odata)
#define OUT1(odata) p9_3=(odata)
#define OUT0(odata) p5_0=(odata)

#define set_out0_output()  set_output(5,0)
#define set_out1_output()  set_output(9,3)
#define set_out2_output()  set_output(9,2)
#define set_out3_output()  set_output(9,1)
#define set_out4_output()  set_output(9,0)
#define set_out5_output()  set_output(2,7)
//about input

#define set_in0_input() set_input(5,2)
#define set_in1_input() set_input(5,3)
#define set_in2_input() set_input(5,4)
#define set_in3_input() set_input(4,4)
#define set_in4_input() set_input(4,3)
#define set_in5_input() set_input(5,5)
#define set_in6_input() set_input(5,6)
#define set_in7_input() set_input(5,7)

#define IN0_PIN p5_2
#define IN1_PIN p5_3
#define IN2_PIN p5_4
#define IN3_PIN p4_4
#define IN4_PIN p4_3
#define IN5_PIN p5_5
#define IN6_PIN p5_6
#define IN7_PIN p5_7

//about running led
#define RUN_LED_ON() p3_1=0
#define RUN_LED_OFF() p3_1=1
#define RUN_LED_CTRL() set_output(3, 1);

//about keyboard

#define KEYBOARD_ROW 1
#define KEYBOARD_LINE 3
#define set_keycol1_port_input()      set_input(7,1)
#define set_keycol2_port_input()      set_input(7,2)
#define set_keycol3_port_input()      set_input(7,3)
#define keycol1_in p7_1
#define keycol2_in p7_2
#define keycol3_in p7_3

//about display

#ifdef __SIMPLE_DISPLAY__
    #define LED_B1(value)			p7_7=(value)
    #define set_led_seg1_output() set_output(7, 7);
    #define LED_B2(value)			p7_6=(value)
    #define set_led_seg2_output() set_output(7, 6);
    #define LED_B3(value)			p7_5=(value)
    #define set_led_seg3_output() set_output(7, 5);

    #define	LEDDATAPORT(portdata)		p0=(portdata)
    #define set_led_data_port_output() { \
    set_output(0, 0);\
    set_output(0, 1);\
    set_output(0, 2);\
    set_output(0, 3);\
    set_output(0, 4);\
    set_output(0, 5);\
    set_output(0, 6);\
    set_output(0, 7);\
}
#endif
#endif /* __PORT_H__ */


